
package codeGenerate.mybatis.constants;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

public class DBType {

	public static final String ORACLE = "ORACLE";

	public static final String MYSQL = "MYSQL";

	public static final String SQLSERVER = "SQLSERVER";

	public static final String SQLSERVER2005 = "SQLSERVER2005";

	public static final String DB2 = "DB2";

	public static final String INFORMIX = "INFORMIX";

	public static final String SYBASE = "SYBASE";

	public static final String POSTGRESQL = "POSTGRESQL";

	public static final String TERADATA = "TERADATA";

	public static final String NETEZZA = "NETEZZA";

	public static final String OTHER = "OTHER";

	public static final String EMPTY = "EMPTY";

	public static final String CLICKHOUSE = "CLICKHOUSE";

	public static final String SQLSERVER2017 = "SQLSERVER2017";

	private static final Map<String, String> driverMap = new HashMap<>();

	static {
		// Oracle数据库
		driverMap.put("oracle.jdbc.driver.OracleDriver", ORACLE);
		// MYSQL 数据库
		driverMap.put("com.mysql.jdbc.Driver", MYSQL);
		driverMap.put("com.mysql.cj.jdbc.Driver", MYSQL);
		// SQL SERVER 数据库
		driverMap.put("com.microsoft.sqlserver.jdbc.SQLServerDriver", SQLSERVER2005);
		driverMap.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", SQLSERVER);
		// DB2 数据库
		driverMap.put("com.ibm.db2.jcc.DB2Driver", DB2);
		// INFORMIX 数据库
		driverMap.put("com.informix.jdbc.IfxDriver", INFORMIX);
		// SYBASE 数据库
		driverMap.put("com.sybase.jdbc2.jdbc.SybDriver", SYBASE);
		driverMap.put("com.sybase.jdbc3.jdbc.SybDriver", SYBASE);
		//PostgreSQL
		driverMap.put("org.postgresql.Driver", POSTGRESQL);
		//Teradata
		driverMap.put("com.ncr.teradata.TeraDriver", TERADATA);
		//Netezza
		driverMap.put("org.netezza.Driver", NETEZZA);
		//clickhouse
		driverMap.put("ru.yandex.clickhouse.ClickHouseDriver", CLICKHOUSE);

	}

	/**
	 * @description: 根据驱动名称返回数据库类型
	 * @creator: dw-fu1
	 * @createDate: 2021年5月21日
	 * @param driverName
	 * @return
	 */
	public static String getByDriverName(String driverName) {
		// 空类型
		if (null == driverName || driverName.trim().length() < 1) {
			return EMPTY;
		}
		String type = driverMap.get(driverName.trim());
		if (StringUtils.isNotBlank(type)) {
			return type;
		}
		// 默认,返回其他
		return OTHER;
	}
}
